package com.dd.stack.postgresql.controller;

import com.dd.stack.postgresql.pojo.DO.DepartmentDO;
import com.dd.stack.postgresql.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/2/11 20:37
 * @Description DepartmentController
 */
@RestController
@Api(tags = "DepartmentController")
@RequestMapping("/departments")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @PostMapping
    @ApiOperation("新增部门")
    public boolean addDepartment(@RequestBody DepartmentDO department) {
        return departmentService.save(department);
    }

    @ApiOperation("根据 ID 删除部门")
    @DeleteMapping("/{deptId}")
    public boolean deleteDepartment(@PathVariable Integer deptId) {
        return departmentService.removeById(deptId);
    }

    @PutMapping
    @ApiOperation("根据 ID 更新部门信息")
    public boolean updateDepartment(@RequestBody DepartmentDO department) {
        return departmentService.updateById(department);
    }

    @GetMapping("/{deptId}")
    @ApiOperation("根据 ID 查询部门")
    public DepartmentDO getDepartmentById(@PathVariable Integer deptId) {
        return departmentService.getById(deptId);
    }

    @GetMapping
    @ApiOperation("查询所有部门")
    public List<DepartmentDO> getAllDepartments() {
        return departmentService.list();
    }
}